﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Utility;
using Data;
namespace Website.Teacher
{
    public partial class UC_UploadAssignment : System.Web.UI.UserControl
    {
        Tbl_AssignmentBus Ass_Bus = new Tbl_AssignmentBus();
        Tbl_SubjectBUS subjectBus = new Tbl_SubjectBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadData();
                loadSubject();
            }
        }
        private void loadData()
        {
            GridView1.DataSource = Ass_Bus.getListAssignment();
            GridView1.DataBind();
        }
        private void loadSubject()
        {
            foreach (tbl_subject m in subjectBus.getListSubject())
            {
                DropDownList2.Items.Add(m.subject_id + "-" + m.subject_id);
            }
            DropDownList2.DataBind();

        }
        private void Reset()
        {
            lblID.Text = "";
            txtName.Text = "";
        }
        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            lblID.Text = WebHelper.GetValueGridView(GridView1, 2, e);
            txtName.Text = WebHelper.GetValueGridView(GridView1, 3, e);
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Reset();
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            tbl_assignment ts = new tbl_assignment();
            ts.assignment_id = Int32.Parse(WebHelper.GetDataKey(GridView1, e));
            Ass_Bus.delete(ts);
            loadData();
            Reset();
        }
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Length == 0)
            {
                WebHelper.ShowMessage("Name not null", Page);
            }
            else
            {
                tbl_assignment ts = new tbl_assignment();
                ts.assignment_name = txtName.Text;
                ts.assignment_date = DateTime.Parse(DateSelect1.CalendarDate);
          
            }
        }
        
    }
}